package com.example.zg.androidnewview.behaviors;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * 创建日期:2019/1/10 on 15:42
 * 描述：
 * 作者: zhougan
 */
public class EasyBehavior extends CoordinatorLayout.Behavior<TextView> {
    public EasyBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
        //告知监听的dependency是Button
        return dependency instanceof Button;
    }

    //当 dependency(Button)变化的时候，可以对child(TextView)进行操作
    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
        child.setX( dependency.getX()+dependency.getWidth()/2);
        child.setY( dependency.getY()+dependency.getHeight());

        child.setText(child.getX()+"-"+child.getY());

        return true;
    }

}
